package com.topboya.linker.ui.presenter;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.topboya.linker.api.ApiRetrofit;
import com.topboya.linker.model.response.TencentLocationResponse;
import com.topboya.linker.ui.base.Presenter.BasePresenter;
import com.topboya.linker.ui.base.activity.BaseActivity;
import com.topboya.linker.ui.view.ChangePsView;
import com.topboya.linker.utils.LogUtils;


import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class ChangePsPresenter extends BasePresenter<ChangePsView> {

    private static final String TAG = "ChangePsPresenter";

    public ChangePsPresenter(BaseActivity context) {
        super(context);
    }

    public void modifyPassWord(String oldPassword, String newPassword) {

        ApiRetrofit.getInstance().modifyPassWord(oldPassword,newPassword)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(changePsRespnse -> {
                    mContext.hideWaitingDialog();
                    LogUtils.v(TAG + " arearesopnse:" + changePsRespnse.toString());
                    String success = changePsRespnse.getMeta().getSuccess();
                    if (null != success && Boolean.parseBoolean(success)) {

                        getView().modifyPassWord(changePsRespnse);
                    }

                }, this::getOrgError);
    }


    private void getOrgError(Throwable throwable) {

        LogUtils.v(throwable.getLocalizedMessage());
//        UIUtils.showToast(throwable.getLocalizedMessage());
        LogUtils.v(TAG + "getOrgError:" + throwable.getLocalizedMessage());
        mContext.hideWaitingDialog();

    }
}
